package com.z6school.manage.controller;

import com.z6school.manage.common.pojo.UserMenuVo;
import com.z6school.manage.common.util.ShiroUtils;
import com.z6school.manage.po.User;
import com.z6school.manage.service.MenuService;
import com.z6school.manage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/")
public class PageController {
    private String moduleUI;
    @Autowired
    private MenuService menuService;

    @RequestMapping("doIndexUI")
    public String doIndexUI(Model model){
        User user = ShiroUtils.getUser();
        model.addAttribute("username", user.getUsername());
        List<UserMenuVo> userMenus = menuService.findUserMenusByUserId(user.getId());
        model.addAttribute("userMenus",userMenus);
        return "starter";
    }

    @RequestMapping("doPageUI")
    public String doPageUI() {
        return "common/page";
    }

    @RequestMapping("doLoginUI")
    public String doLoginUI() {
        return "login";
    }

    @RequestMapping("{module}/{moduleUI}")
    public String doModuleUI(@PathVariable String moduleUI){
        return  "sys/"+moduleUI;
    }

}
